home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / gnu-c / src / gcc-2.7.0-amiga / gcc.info-10 (.txt) < prev    next >
GNU Info File  |  1995-06-16  |  51KB  |  885 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.55 from the input
  2. file gcc.texi.
  3.    This file documents the use and the internals of the GNU compiler.
  4.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  5. Boston, MA 02111-1307 USA
  6.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995 Free Software
  7. Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided also
  13. that the sections entitled "GNU General Public License," "Funding for
  14. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  15. included exactly as in the original, and provided that the entire
  16. resulting derived work is distributed under the terms of a permission
  17. notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions, except that the sections entitled "GNU General Public
  21. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  22. `Look And Feel'", and this permission notice, may be included in
  23. translations approved by the Free Software Foundation instead of in the
  24. original English.
  25. File: gcc.info,  Node: Explicit Reg Vars,  Next: Alternate Keywords,  Prev: Asm Labels,  Up: C Extensions
  26. Variables in Specified Registers
  27. ================================
  28.    GNU C allows you to put a few global variables into specified
  29. hardware registers.  You can also specify the register in which an
  30. ordinary register variable should be allocated.
  31.    * Global register variables reserve registers throughout the program.
  32.      This may be useful in programs such as programming language
  33.      interpreters which have a couple of global variables that are
  34.      accessed very often.
  35.    * Local register variables in specific registers do not reserve the
  36.      registers.  The compiler's data flow analysis is capable of
  37.      determining where the specified registers contain live values, and
  38.      where they are available for other uses.
  39.      These local variables are sometimes convenient for use with the
  40.      extended `asm' feature (*note Extended Asm::.), if you want to
  41.      write one output of the assembler instruction directly into a
  42.      particular register.  (This will work provided the register you
  43.      specify fits the constraints specified for that operand in the
  44.      `asm'.)
  45. * Menu:
  46. * Global Reg Vars::
  47. * Local Reg Vars::
  48. File: gcc.info,  Node: Global Reg Vars,  Next: Local Reg Vars,  Up: Explicit Reg Vars
  49. Defining Global Register Variables
  50. ----------------------------------
  51.    You can define a global register variable in GNU C like this:
  52.      register int *foo asm ("a5");
  53. Here `a5' is the name of the register which should be used.  Choose a
  54. register which is normally saved and restored by function calls on your
  55. machine, so that library routines will not clobber it.
  56.    Naturally the register name is cpu-dependent, so you would need to
  57. conditionalize your program according to cpu type.  The register `a5'
  58. would be a good choice on a 68000 for a variable of pointer type.  On
  59. machines with register windows, be sure to choose a "global" register
  60. that is not affected magically by the function call mechanism.
  61.    In addition, operating systems on one type of cpu may differ in how
  62. they name the registers; then you would need additional conditionals.
  63. For example, some 68000 operating systems call this register `%a5'.
  64.    Eventually there may be a way of asking the compiler to choose a
  65. register automatically, but first we need to figure out how it should
  66. choose and how to enable you to guide the choice.  No solution is
  67. evident.
  68.    Defining a global register variable in a certain register reserves
  69. that register entirely for this use, at least within the current
  70. compilation.  The register will not be allocated for any other purpose
  71. in the functions in the current compilation.  The register will not be
  72. saved and restored by these functions.  Stores into this register are
  73. never deleted even if they would appear to be dead, but references may
  74. be deleted or moved or simplified.
  75.    It is not safe to access the global register variables from signal
  76. handlers, or from more than one thread of control, because the system
  77. library routines may temporarily use the register for other things
  78. (unless you recompile them specially for the task at hand).
  79.    It is not safe for one function that uses a global register variable
  80. to call another such function `foo' by way of a third function `lose'
  81. that was compiled without knowledge of this variable (i.e. in a
  82. different source file in which the variable wasn't declared).  This is
  83. because `lose' might save the register and put some other value there.
  84. For example, you can't expect a global register variable to be
  85. available in the comparison-function that you pass to `qsort', since
  86. `qsort' might have put something else in that register.  (If you are
  87. prepared to recompile `qsort' with the same global register variable,
  88. you can solve this problem.)
  89.    If you want to recompile `qsort' or other source files which do not
  90. actually use your global register variable, so that they will not use
  91. that register for any other purpose, then it suffices to specify the
  92. compiler option `-ffixed-REG'.  You need not actually add a global
  93. register declaration to their source code.
  94.    A function which can alter the value of a global register variable
  95. cannot safely be called from a function compiled without this variable,
  96. because it could clobber the value the caller expects to find there on
  97. return.  Therefore, the function which is the entry point into the part
  98. of the program that uses the global register variable must explicitly
  99. save and restore the value which belongs to its caller.
  100.    On most machines, `longjmp' will restore to each global register
  101. variable the value it had at the time of the `setjmp'.  On some
  102. machines, however, `longjmp' will not change the value of global
  103. register variables.  To be portable, the function that called `setjmp'
  104. should make other arrangements to save the values of the global register
  105. variables, and to restore them in a `longjmp'.  This way, the same
  106. thing will happen regardless of what `longjmp' does.
  107.    All global register variable declarations must precede all function
  108. definitions.  If such a declaration could appear after function
  109. definitions, the declaration would be too late to prevent the register
  110. from being used for other purposes in the preceding functions.
  111.    Global register variables may not have initial values, because an
  112. executable file has no means to supply initial contents for a register.
  113.    On the Sparc, there are reports that g3 ... g7 are suitable
  114. registers, but certain library functions, such as `getwd', as well as
  115. the subroutines for division and remainder, modify g3 and g4.  g1 and
  116. g2 are local temporaries.
  117.    On the 68000, a2 ... a5 should be suitable, as should d2 ... d7.  Of
  118. course, it will not do to use more than a few of those.
  119. File: gcc.info,  Node: Local Reg Vars,  Prev: Global Reg Vars,  Up: Explicit Reg Vars
  120. Specifying Registers for Local Variables
  121. ----------------------------------------
  122.    You can define a local register variable with a specified register
  123. like this:
  124.      register int *foo asm ("a5");
  125. Here `a5' is the name of the register which should be used.  Note that
  126. this is the same syntax used for defining global register variables,
  127. but for a local variable it would appear within a function.
  128.    Naturally the register name is cpu-dependent, but this is not a
  129. problem, since specific registers are most often useful with explicit
  130. assembler instructions (*note Extended Asm::.).  Both of these things
  131. generally require that you conditionalize your program according to cpu
  132. type.
  133.    In addition, operating systems on one type of cpu may differ in how
  134. they name the registers; then you would need additional conditionals.
  135. For example, some 68000 operating systems call this register `%a5'.
  136.    Eventually there may be a way of asking the compiler to choose a
  137. register automatically, but first we need to figure out how it should
  138. choose and how to enable you to guide the choice.  No solution is
  139. evident.
  140.    Defining such a register variable does not reserve the register; it
  141. remains available for other uses in places where flow control determines
  142. the variable's value is not live.  However, these registers are made
  143. unavailable for use in the reload pass.  I would not be surprised if
  144. excessive use of this feature leaves the compiler too few available
  145. registers to compile certain functions.
  146. File: gcc.info,  Node: Alternate Keywords,  Next: Incomplete Enums,  Prev: Explicit Reg Vars,  Up: C Extensions
  147. Alternate Keywords
  148. ==================
  149.    The option `-traditional' disables certain keywords; `-ansi'
  150. disables certain others.  This causes trouble when you want to use GNU C
  151. extensions, or ANSI C features, in a general-purpose header file that
  152. should be usable by all programs, including ANSI C programs and
  153. traditional ones.  The keywords `asm', `typeof' and `inline' cannot be
  154. used since they won't work in a program compiled with `-ansi', while
  155. the keywords `const', `volatile', `signed', `typeof' and `inline' won't
  156. work in a program compiled with `-traditional'.
  157.    The way to solve these problems is to put `__' at the beginning and
  158. end of each problematical keyword.  For example, use `__asm__' instead
  159. of `asm', `__const__' instead of `const', and `__inline__' instead of
  160. `inline'.
  161.    Other C compilers won't accept these alternative keywords; if you
  162. want to compile with another compiler, you can define the alternate
  163. keywords as macros to replace them with the customary keywords.  It
  164. looks like this:
  165.      #ifndef __GNUC__
  166.      #define __asm__ asm
  167.      #endif
  168.    `-pedantic' causes warnings for many GNU C extensions.  You can
  169. prevent such warnings within one expression by writing `__extension__'
  170. before the expression.  `__extension__' has no effect aside from this.
  171. File: gcc.info,  Node: Incomplete Enums,  Next: Function Names,  Prev: Alternate Keywords,  Up: C Extensions
  172. Incomplete `enum' Types
  173. =======================
  174.    You can define an `enum' tag without specifying its possible values.
  175. This results in an incomplete type, much like what you get if you write
  176. `struct foo' without describing the elements.  A later declaration
  177. which does specify the possible values completes the type.
  178.    You can't allocate variables or storage using the type while it is
  179. incomplete.  However, you can work with pointers to that type.
  180.    This extension may not be very useful, but it makes the handling of
  181. `enum' more consistent with the way `struct' and `union' are handled.
  182.    This extension is not supported by GNU C++.
  183. File: gcc.info,  Node: Function Names,  Prev: Incomplete Enums,  Up: C Extensions
  184. Function Names as Strings
  185. =========================
  186.    GNU CC predefines two string variables to be the name of the current
  187. function.  The variable `__FUNCTION__' is the name of the function as
  188. it appears in the source.  The variable `__PRETTY_FUNCTION__' is the
  189. name of the function pretty printed in a language specific fashion.
  190.    These names are always the same in a C function, but in a C++
  191. function they may be different.  For example, this program:
  192.      extern "C" {
  193.      extern int printf (char *, ...);
  194.      }
  195.      
  196.      class a {
  197.       public:
  198.        sub (int i)
  199.          {
  200.            printf ("__FUNCTION__ = %s\n", __FUNCTION__);
  201.            printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
  202.          }
  203.      };
  204.      
  205.      int
  206.      main (void)
  207.      {
  208.        a ax;
  209.        ax.sub (0);
  210.        return 0;
  211.      }
  212. gives this output:
  213.      __FUNCTION__ = sub
  214.      __PRETTY_FUNCTION__ = int  a::sub (int)
  215. File: gcc.info,  Node: C++ Extensions,  Next: Trouble,  Prev: C Extensions,  Up: Top
  216. Extensions to the C++ Language
  217. ******************************
  218.    The GNU compiler provides these extensions to the C++ language (and
  219. you can also use most of the C language extensions in your C++
  220. programs).  If you want to write code that checks whether these
  221. features are available, you can test for the GNU compiler the same way
  222. as for C programs: check for a predefined macro `__GNUC__'.  You can
  223. also use `__GNUG__' to test specifically for GNU C++ (*note Standard
  224. Predefined Macros: (cpp.info)Standard Predefined.).
  225. * Menu:
  226. * Naming Results::      Giving a name to C++ function return values.
  227. * Min and Max::        C++ Minimum and maximum operators.
  228. * Destructors and Goto:: Goto is safe to use in C++ even when destructors
  229.                            are needed.
  230. * C++ Interface::       You can use a single C++ header file for both
  231.                          declarations and definitions.
  232. * Template Instantiation:: Methods for ensuring that exactly one copy of
  233.                          each needed template instantiation is emitted.
  234. * C++ Signatures::    You can specify abstract types to get subtype
  235.              polymorphism independent from inheritance.
  236. File: gcc.info,  Node: Naming Results,  Next: Min and Max,  Up: C++ Extensions
  237. Named Return Values in C++
  238. ==========================
  239.    GNU C++ extends the function-definition syntax to allow you to
  240. specify a name for the result of a function outside the body of the
  241. definition, in C++ programs:
  242.      TYPE
  243.      FUNCTIONNAME (ARGS) return RESULTNAME;
  244.      {
  245.        ...
  246.        BODY
  247.        ...
  248.      }
  249.    You can use this feature to avoid an extra constructor call when a
  250. function result has a class type.  For example, consider a function
  251. `m', declared as `X v = m ();', whose result is of class `X':
  252.      X
  253.      m ()
  254.      {
  255.        X b;
  256.        b.a = 23;
  257.        return b;
  258.      }
  259.    Although `m' appears to have no arguments, in fact it has one
  260. implicit argument: the address of the return value.  At invocation, the
  261. address of enough space to hold `v' is sent in as the implicit argument.
  262. Then `b' is constructed and its `a' field is set to the value 23.
  263. Finally, a copy constructor (a constructor of the form `X(X&)') is
  264. applied to `b', with the (implicit) return value location as the
  265. target, so that `v' is now bound to the return value.
  266.    But this is wasteful.  The local `b' is declared just to hold
  267. something that will be copied right out.  While a compiler that
  268. combined an "elision" algorithm with interprocedural data flow analysis
  269. could conceivably eliminate all of this, it is much more practical to
  270. allow you to assist the compiler in generating efficient code by
  271. manipulating the return value explicitly, thus avoiding the local
  272. variable and copy constructor altogether.
  273.    Using the extended GNU C++ function-definition syntax, you can avoid
  274. the temporary allocation and copying by naming `r' as your return value
  275. at the outset, and assigning to its `a' field directly:
  276.      X
  277.      m () return r;
  278.      {
  279.        r.a = 23;
  280.      }
  281. The declaration of `r' is a standard, proper declaration, whose effects
  282. are executed *before* any of the body of `m'.
  283.    Functions of this type impose no additional restrictions; in
  284. particular, you can execute `return' statements, or return implicitly by
  285. reaching the end of the function body ("falling off the edge").  Cases
  286.      X
  287.      m () return r (23);
  288.      {
  289.        return;
  290.      }
  291. (or even `X m () return r (23); { }') are unambiguous, since the return
  292. value `r' has been initialized in either case.  The following code may
  293. be hard to read, but also works predictably:
  294.      X
  295.      m () return r;
  296.      {
  297.        X b;
  298.        return b;
  299.      }
  300.    The return value slot denoted by `r' is initialized at the outset,
  301. but the statement `return b;' overrides this value.  The compiler deals
  302. with this by destroying `r' (calling the destructor if there is one, or
  303. doing nothing if there is not), and then reinitializing `r' with `b'.
  304.    This extension is provided primarily to help people who use
  305. overloaded operators, where there is a great need to control not just
  306. the arguments, but the return values of functions.  For classes where
  307. the copy constructor incurs a heavy performance penalty (especially in
  308. the common case where there is a quick default constructor), this is a
  309. major savings.  The disadvantage of this extension is that you do not
  310. control when the default constructor for the return value is called: it
  311. is always called at the beginning.
  312. File: gcc.info,  Node: Min and Max,  Next: Destructors and Goto,  Prev: Naming Results,  Up: C++ Extensions
  313. Minimum and Maximum Operators in C++
  314. ====================================
  315.    It is very convenient to have operators which return the "minimum"
  316. or the "maximum" of two arguments.  In GNU C++ (but not in GNU C),
  317. `A <? B'
  318.      is the "minimum", returning the smaller of the numeric values A
  319.      and B;
  320. `A >? B'
  321.      is the "maximum", returning the larger of the numeric values A and
  322.      B.
  323.    These operations are not primitive in ordinary C++, since you can
  324. use a macro to return the minimum of two things in C++, as in the
  325. following example.
  326.      #define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
  327. You might then use `int min = MIN (i, j);' to set MIN to the minimum
  328. value of variables I and J.
  329.    However, side effects in `X' or `Y' may cause unintended behavior.
  330. For example, `MIN (i++, j++)' will fail, incrementing the smaller
  331. counter twice.  A GNU C extension allows you to write safe macros that
  332. avoid this kind of problem (*note Naming an Expression's Type: Naming
  333. Types.).  However, writing `MIN' and `MAX' as macros also forces you to
  334. use function-call notation notation for a fundamental arithmetic
  335. operation.  Using GNU C++ extensions, you can write `int min = i <? j;'
  336. instead.
  337.    Since `<?' and `>?' are built into the compiler, they properly
  338. handle expressions with side-effects;  `int min = i++ <? j++;' works
  339. correctly.
  340. File: gcc.info,  Node: Destructors and Goto,  Next: C++ Interface,  Prev: Min and Max,  Up: C++ Extensions
  341. `goto' and Destructors in GNU C++
  342. =================================
  343.    In C++ programs, you can safely use the `goto' statement.  When you
  344. use it to exit a block which contains aggregates requiring destructors,
  345. the destructors will run before the `goto' transfers control.  (In ANSI
  346. C++, `goto' is restricted to targets within the current block.)
  347.    The compiler still forbids using `goto' to *enter* a scope that
  348. requires constructors.
  349. File: gcc.info,  Node: C++ Interface,  Next: Template Instantiation,  Prev: Destructors and Goto,  Up: C++ Extensions
  350. Declarations and Definitions in One Header
  351. ==========================================
  352.    C++ object definitions can be quite complex.  In principle, your
  353. source code will need two kinds of things for each object that you use
  354. across more than one source file.  First, you need an "interface"
  355. specification, describing its structure with type declarations and
  356. function prototypes.  Second, you need the "implementation" itself.  It
  357. can be tedious to maintain a separate interface description in a header
  358. file, in parallel to the actual implementation.  It is also dangerous,
  359. since separate interface and implementation definitions may not remain
  360. parallel.
  361.    With GNU C++, you can use a single header file for both purposes.
  362.      *Warning:* The mechanism to specify this is in transition.  For the
  363.      nonce, you must use one of two `#pragma' commands; in a future
  364.      release of GNU C++, an alternative mechanism will make these
  365.      `#pragma' commands unnecessary.
  366.    The header file contains the full definitions, but is marked with
  367. `#pragma interface' in the source code.  This allows the compiler to
  368. use the header file only as an interface specification when ordinary
  369. source files incorporate it with `#include'.  In the single source file
  370. where the full implementation belongs, you can use either a naming
  371. convention or `#pragma implementation' to indicate this alternate use
  372. of the header file.
  373. `#pragma interface'
  374. `#pragma interface "SUBDIR/OBJECTS.h"'
  375.      Use this directive in *header files* that define object classes,
  376.      to save space in most of the object files that use those classes.
  377.      Normally, local copies of certain information (backup copies of
  378.      inline member functions, debugging information, and the internal
  379.      tables that implement virtual functions) must be kept in each
  380.      object file that includes class definitions.  You can use this
  381.      pragma to avoid such duplication.  When a header file containing
  382.      `#pragma interface' is included in a compilation, this auxiliary
  383.      information will not be generated (unless the main input source
  384.      file itself uses `#pragma implementation').  Instead, the object
  385.      files will contain references to be resolved at link time.
  386.      The second form of this directive is useful for the case where you
  387.      have multiple headers with the same name in different directories.
  388.      If you use this form, you must specify the same string to `#pragma
  389.      implementation'.
  390. `#pragma implementation'
  391. `#pragma implementation "OBJECTS.h"'
  392.      Use this pragma in a *main input file*, when you want full output
  393.      from included header files to be generated (and made globally
  394.      visible).  The included header file, in turn, should use `#pragma
  395.      interface'.  Backup copies of inline member functions, debugging
  396.      information, and the internal tables used to implement virtual
  397.      functions are all generated in implementation files.
  398.      If you use `#pragma implementation' with no argument, it applies to
  399.      an include file with the same basename(1) as your source file.
  400.      For example, in `allclass.cc', `#pragma implementation' by itself
  401.      is equivalent to `#pragma implementation "allclass.h"'.
  402.      In versions of GNU C++ prior to 2.6.0 `allclass.h' was treated as
  403.      an implementation file whenever you would include it from
  404.      `allclass.cc' even if you never specified `#pragma
  405.      implementation'.  This was deemed to be more trouble than it was
  406.      worth, however, and disabled.
  407.      If you use an explicit `#pragma implementation', it must appear in
  408.      your source file *before* you include the affected header files.
  409.      Use the string argument if you want a single implementation file to
  410.      include code from multiple header files.  (You must also use
  411.      `#include' to include the header file; `#pragma implementation'
  412.      only specifies how to use the file--it doesn't actually include
  413.      it.)
  414.      There is no way to split up the contents of a single header file
  415.      into multiple implementation files.
  416.    `#pragma implementation' and `#pragma interface' also have an effect
  417. on function inlining.
  418.    If you define a class in a header file marked with `#pragma
  419. interface', the effect on a function defined in that class is similar to
  420. an explicit `extern' declaration--the compiler emits no code at all to
  421. define an independent version of the function.  Its definition is used
  422. only for inlining with its callers.
  423.    Conversely, when you include the same header file in a main source
  424. file that declares it as `#pragma implementation', the compiler emits
  425. code for the function itself; this defines a version of the function
  426. that can be found via pointers (or by callers compiled without
  427. inlining).  If all calls to the function can be inlined, you can avoid
  428. emitting the function by compiling with `-fno-implement-inlines'.  If
  429. any calls were not inlined, you will get linker errors.
  430.    ---------- Footnotes ----------
  431.    (1)  A file's "basename" was the name stripped of all leading path
  432. information and of trailing suffixes, such as `.h' or `.C' or `.cc'.
  433. File: gcc.info,  Node: Template Instantiation,  Next: C++ Signatures,  Prev: C++ Interface,  Up: C++ Extensions
  434. Where's the Template?
  435. =====================
  436.    C++ templates are the first language feature to require more
  437. intelligence from the environment than one usually finds on a UNIX
  438. system.  Somehow the compiler and linker have to make sure that each
  439. template instance occurs exactly once in the executable if it is needed,
  440. and not at all otherwise.  There are two basic approaches to this
  441. problem, which I will refer to as the Borland model and the Cfront
  442. model.
  443. Borland model
  444.      Borland C++ solved the template instantiation problem by adding
  445.      the code equivalent of common blocks to their linker; template
  446.      instances are emitted in each translation unit that uses them, and
  447.      they are collapsed together at run time.  The advantage of this
  448.      model is that the linker only has to consider the object files
  449.      themselves; there is no external complexity to worry about.  This
  450.      disadvantage is that compilation time is increased because the
  451.      template code is being compiled repeatedly.  Code written for this
  452.      model tends to include definitions of all member templates in the
  453.      header file, since they must be seen to be compiled.
  454. Cfront model
  455.      The AT&T C++ translator, Cfront, solved the template instantiation
  456.      problem by creating the notion of a template repository, an
  457.      automatically maintained place where template instances are
  458.      stored.  As individual object files are built, notes are placed in
  459.      the repository to record where templates and potential type
  460.      arguments were seen so that the subsequent instantiation step
  461.      knows where to find them.  At link time, any needed instances are
  462.      generated and linked in.  The advantages of this model are more
  463.      optimal compilation speed and the ability to use the system
  464.      linker; to implement the Borland model a compiler vendor also
  465.      needs to replace the linker.  The disadvantages are vastly
  466.      increased complexity, and thus potential for error; theoretically,
  467.      this should be just as transparent, but in practice it has been
  468.      very difficult to build multiple programs in one directory and one
  469.      program in multiple directories using Cfront.  Code written for
  470.      this model tends to separate definitions of non-inline member
  471.      templates into a separate file, which is magically found by the
  472.      link preprocessor when a template needs to be instantiated.
  473.    Currently, g++ implements neither automatic model.  The g++ team
  474. hopes to have a repository working for 2.7.0.  In the mean time, you
  475. have three options for dealing with template instantiations:
  476.   1. Do nothing.  Pretend g++ does implement automatic instantiation
  477.      management.  Code written for the Borland model will work fine, but
  478.      each translation unit will contain instances of each of the
  479.      templates it uses.  In a large program, this can lead to an
  480.      unacceptable amount of code duplication.
  481.   2. Add `#pragma interface' to all files containing template
  482.      definitions.  For each of these files, add `#pragma implementation
  483.      "FILENAME"' to the top of some `.C' file which `#include's it.
  484.      Then compile everything with -fexternal-templates.  The templates
  485.      will then only be expanded in the translation unit which
  486.      implements them (i.e. has a `#pragma implementation' line for the
  487.      file where they live); all other files will use external
  488.      references.  If you're lucky, everything should work properly.  If
  489.      you get undefined symbol errors, you need to make sure that each
  490.      template instance which is used in the program is used in the file
  491.      which implements that template.  If you don't have any use for a
  492.      particular instance in that file, you can just instantiate it
  493.      explicitly, using the syntax from the latest C++ working paper:
  494.           template class A<int>;
  495.           template ostream& operator << (ostream&, const A<int>&);
  496.      This strategy will work with code written for either model.  If
  497.      you are using code written for the Cfront model, the file
  498.      containing a class template and the file containing its member
  499.      templates should be implemented in the same translation unit.
  500.      A slight variation on this approach is to use the flag
  501.      -falt-external-templates instead; this flag causes template
  502.      instances to be emitted in the translation unit that implements
  503.      the header where they are first instantiated, rather than the one
  504.      which implements the file where the templates are defined.  This
  505.      header must be the same in all translation units, or things are
  506.      likely to break.
  507.      *Note Declarations and Definitions in One Header: C++ Interface,
  508.      for more discussion of these pragmas.
  509.   3. Explicitly instantiate all the template instances you use, and
  510.      compile with -fno-implicit-templates.  This is probably your best
  511.      bet; it may require more knowledge of exactly which templates you
  512.      are using, but it's less mysterious than the previous approach,
  513.      and it doesn't require any `#pragma's or other g++-specific code.
  514.      You can scatter the instantiations throughout your program, you
  515.      can create one big file to do all the instantiations, or you can
  516.      create tiny files like
  517.           #include "Foo.h"
  518.           #include "Foo.cc"
  519.           
  520.           template class Foo<int>;
  521.      for each instance you need, and create a template instantiation
  522.      library from those.  I'm partial to the last, but your mileage may
  523.      vary.  If you are using Cfront-model code, you can probably get
  524.      away with not using -fno-implicit-templates when compiling files
  525.      that don't `#include' the member template definitions.
  526. File: gcc.info,  Node: C++ Signatures,  Prev: Template Instantiation,  Up: C++ Extensions
  527. Type Abstraction using Signatures
  528. =================================
  529.    In GNU C++, you can use the keyword `signature' to define a
  530. completely abstract class interface as a datatype.  You can connect this
  531. abstraction with actual classes using signature pointers.  If you want
  532. to use signatures, run the GNU compiler with the `-fhandle-signatures'
  533. command-line option.  (With this option, the compiler reserves a second
  534. keyword `sigof' as well, for a future extension.)
  535.    Roughly, signatures are type abstractions or interfaces of classes.
  536. Some other languages have similar facilities.  C++ signatures are
  537. related to ML's signatures, Haskell's type classes, definition modules
  538. in Modula-2, interface modules in Modula-3, abstract types in Emerald,
  539. type modules in Trellis/Owl, categories in Scratchpad II, and types in
  540. POOL-I.  For a more detailed discussion of signatures, see `Signatures:
  541. A C++ Extension for Type Abstraction and Subtype Polymorphism' by
  542. Gerald Baumgartner and Vincent F. Russo (Tech report CSD-TR-93-059,
  543. Dept. of Computer Sciences, Purdue University, December 1994, to appear
  544. in *Software Practice & Experience*).  You can get the tech report by
  545. anonymous FTP from `ftp.cs.purdue.edu' in `pub/reports/TR93-059.PS.Z'.
  546.    Syntactically, a signature declaration is a collection of member
  547. function declarations and nested type declarations.  For example, this
  548. signature declaration defines a new abstract type `S' with member
  549. functions `int foo ()' and `int bar (int)':
  550.      signature S
  551.      {
  552.        int foo ();
  553.        int bar (int);
  554.      };
  555.    Since signature types do not include implementation definitions, you
  556. cannot write an instance of a signature directly.  Instead, you can
  557. define a pointer to any class that contains the required interfaces as a
  558. "signature pointer".  Such a class "implements" the signature type.
  559.    To use a class as an implementation of `S', you must ensure that the
  560. class has public member functions `int foo ()' and `int bar (int)'.
  561. The class can have other member functions as well, public or not; as
  562. long as it offers what's declared in the signature, it is suitable as
  563. an implementation of that signature type.
  564.    For example, suppose that `C' is a class that meets the requirements
  565. of signature `S' (`C' "conforms to" `S').  Then
  566.      C obj;
  567.      S * p = &obj;
  568. defines a signature pointer `p' and initializes it to point to an
  569. object of type `C'.  The member function call `int i = p->foo ();'
  570. executes `obj.foo ()'.
  571.    Abstract virtual classes provide somewhat similar facilities in
  572. standard C++.  There are two main advantages to using signatures
  573. instead:
  574.   1. Subtyping becomes independent from inheritance.  A class or
  575.      signature type `T' is a subtype of a signature type `S'
  576.      independent of any inheritance hierarchy as long as all the member
  577.      functions declared in `S' are also found in `T'.  So you can
  578.      define a subtype hierarchy that is completely independent from any
  579.      inheritance (implementation) hierarchy, instead of being forced to
  580.      use types that mirror the class inheritance hierarchy.
  581.   2. Signatures allow you to work with existing class hierarchies as
  582.      implementations of a signature type.  If those class hierarchies
  583.      are only available in compiled form, you're out of luck with
  584.      abstract virtual classes, since an abstract virtual class cannot
  585.      be retrofitted on top of existing class hierarchies.  So you would
  586.      be required to write interface classes as subtypes of the abstract
  587.      virtual class.
  588.    There is one more detail about signatures.  A signature declaration
  589. can contain member function *definitions* as well as member function
  590. declarations.  A signature member function with a full definition is
  591. called a *default implementation*; classes need not contain that
  592. particular interface in order to conform.  For example, a class `C' can
  593. conform to the signature
  594.      signature T
  595.      {
  596.        int f (int);
  597.        int f0 () { return f (0); };
  598.      };
  599. whether or not `C' implements the member function `int f0 ()'.  If you
  600. define `C::f0', that definition takes precedence; otherwise, the
  601. default implementation `S::f0' applies.
  602. File: gcc.info,  Node: Trouble,  Next: Bugs,  Prev: C++ Extensions,  Up: Top
  603. Known Causes of Trouble with GNU CC
  604. ***********************************
  605.    This section describes known problems that affect users of GNU CC.
  606. Most of these are not GNU CC bugs per se--if they were, we would fix
  607. them.  But the result for a user may be like the result of a bug.
  608.    Some of these problems are due to bugs in other software, some are
  609. missing features that are too much work to add, and some are places
  610. where people's opinions differ as to what is best.
  611. * Menu:
  612. * Actual Bugs::              Bugs we will fix later.
  613. * Installation Problems::     Problems that manifest when you install GNU CC.
  614. * Cross-Compiler Problems::   Common problems of cross compiling with GNU CC.
  615. * Interoperation::      Problems using GNU CC with other compilers,
  616.                and with certain linkers, assemblers and debuggers.
  617. * External Bugs::    Problems compiling certain programs.
  618. * Incompatibilities::   GNU CC is incompatible with traditional C.
  619. * Fixed Headers::       GNU C uses corrected versions of system header files.
  620.                            This is necessary, but doesn't always work smoothly.
  621. * Standard Libraries::  GNU C uses the system C library, which might not be
  622.                            compliant with the ISO/ANSI C standard.
  623. * Disappointments::     Regrettable things we can't change, but not quite bugs.
  624. * C++ Misunderstandings::     Common misunderstandings with GNU C++.
  625. * Protoize Caveats::    Things to watch out for when using `protoize'.
  626. * Non-bugs::        Things we think are right, but some others disagree.
  627. * Warnings and Errors:: Which problems in your code get warnings,
  628.                          and which get errors.
  629. File: gcc.info,  Node: Actual Bugs,  Next: Installation Problems,  Up: Trouble
  630. Actual Bugs We Haven't Fixed Yet
  631. ================================
  632.    * The `fixincludes' script interacts badly with automounters; if the
  633.      directory of system header files is automounted, it tends to be
  634.      unmounted while `fixincludes' is running.  This would seem to be a
  635.      bug in the automounter.  We don't know any good way to work around
  636.      it.
  637.    * The `fixproto' script will sometimes add prototypes for the
  638.      `sigsetjmp' and `siglongjmp' functions that reference the
  639.      `jmp_buf' type before that type is defined.  To work around this,
  640.      edit the offending file and place the typedef in front of the
  641.      prototypes.
  642.    * There are several obscure case of mis-using struct, union, and
  643.      enum tags that are not detected as errors by the compiler.
  644.    * When `-pedantic-errors' is specified, GNU C will incorrectly give
  645.      an error message when a function name is specified in an expression
  646.      involving the comma operator.
  647.    * Loop unrolling doesn't work properly for certain C++ programs.
  648.      This is a bug in the C++ front end.  It sometimes emits incorrect
  649.      debug info, and the loop unrolling code is unable to recover from
  650.      this error.
  651. File: gcc.info,  Node: Installation Problems,  Next: Cross-Compiler Problems,  Prev: Actual Bugs,  Up: Trouble
  652. Installation Problems
  653. =====================
  654.    This is a list of problems (and some apparent problems which don't
  655. really mean anything is wrong) that show up during installation of GNU
  656.    * On certain systems, defining certain environment variables such as
  657.      `CC' can interfere with the functioning of `make'.
  658.    * If you encounter seemingly strange errors when trying to build the
  659.      compiler in a directory other than the source directory, it could
  660.      be because you have previously configured the compiler in the
  661.      source directory.  Make sure you have done all the necessary
  662.      preparations.  *Note Other Dir::.
  663.    * If you build GNU CC on a BSD system using a directory stored in a
  664.      System V file system, problems may occur in running `fixincludes'
  665.      if the System V file system doesn't support symbolic links.  These
  666.      problems result in a failure to fix the declaration of `size_t' in
  667.      `sys/types.h'.  If you find that `size_t' is a signed type and
  668.      that type mismatches occur, this could be the cause.
  669.      The solution is not to use such a directory for building GNU CC.
  670.    * In previous versions of GNU CC, the `gcc' driver program looked for
  671.      `as' and `ld' in various places; for example, in files beginning
  672.      with `/usr/local/lib/gcc-'.  GNU CC version 2 looks for them in
  673.      the directory `/usr/local/lib/gcc-lib/TARGET/VERSION'.
  674.      Thus, to use a version of `as' or `ld' that is not the system
  675.      default, for example `gas' or GNU `ld', you must put them in that
  676.      directory (or make links to them from that directory).
  677.    * Some commands executed when making the compiler may fail (return a
  678.      non-zero status) and be ignored by `make'.  These failures, which
  679.      are often due to files that were not found, are expected, and can
  680.      safely be ignored.
  681.    * It is normal to have warnings in compiling certain files about
  682.      unreachable code and about enumeration type clashes.  These files'
  683.      names begin with `insn-'.  Also, `real.c' may get some warnings
  684.      that you can ignore.
  685.    * Sometimes `make' recompiles parts of the compiler when installing
  686.      the compiler.  In one case, this was traced down to a bug in
  687.      `make'.  Either ignore the problem or switch to GNU Make.
  688.    * If you have installed a program known as purify, you may find that
  689.      it causes errors while linking `enquire', which is part of building
  690.      GNU CC.  The fix is to get rid of the file `real-ld' which purify
  691.      installs--so that GNU CC won't try to use it.
  692.    * On Linux SLS 1.01, there is a problem with `libc.a': it does not
  693.      contain the obstack functions.  However, GNU CC assumes that the
  694.      obstack functions are in `libc.a' when it is the GNU C library.
  695.      To work around this problem, change the `__GNU_LIBRARY__'
  696.      conditional around line 31 to `#if 1'.
  697.    * On some 386 systems, building the compiler never finishes because
  698.      `enquire' hangs due to a hardware problem in the motherboard--it
  699.      reports floating point exceptions to the kernel incorrectly.  You
  700.      can install GNU CC except for `float.h' by patching out the
  701.      command to run `enquire'.  You may also be able to fix the problem
  702.      for real by getting a replacement motherboard.  This problem was
  703.      observed in Revision E of the Micronics motherboard, and is fixed
  704.      in Revision F.  It has also been observed in the MYLEX MXA-33
  705.      motherboard.
  706.      If you encounter this problem, you may also want to consider
  707.      removing the FPU from the socket during the compilation.
  708.      Alternatively, if you are running SCO Unix, you can reboot and
  709.      force the FPU to be ignored.  To do this, type `hd(40)unix auto
  710.      ignorefpu'.
  711.    * On some 386 systems, GNU CC crashes trying to compile `enquire.c'.
  712.      This happens on machines that don't have a 387 FPU chip.  On 386
  713.      machines, the system kernel is supposed to emulate the 387 when you
  714.      don't have one.  The crash is due to a bug in the emulator.
  715.      One of these systems is the Unix from Interactive Systems: 386/ix.
  716.      On this system, an alternate emulator is provided, and it does
  717.      work.  To use it, execute this command as super-user:
  718.           ln /etc/emulator.rel1 /etc/emulator
  719.      and then reboot the system.  (The default emulator file remains
  720.      present under the name `emulator.dflt'.)
  721.      Try using `/etc/emulator.att', if you have such a problem on the
  722.      SCO system.
  723.      Another system which has this problem is Esix.  We don't know
  724.      whether it has an alternate emulator that works.
  725.      On NetBSD 0.8, a similar problem manifests itself as these error
  726.      messages:
  727.           enquire.c: In function `fprop':
  728.           enquire.c:2328: floating overflow
  729.    * On SCO systems, when compiling GNU CC with the system's compiler,
  730.      do not use `-O'.  Some versions of the system's compiler miscompile
  731.      GNU CC with `-O'.
  732.    * Sometimes on a Sun 4 you may observe a crash in the program
  733.      `genflags' or `genoutput' while building GNU CC.  This is said to
  734.      be due to a bug in `sh'.  You can probably get around it by running
  735.      `genflags' or `genoutput' manually and then retrying the `make'.
  736.    * On Solaris 2, executables of GNU CC version 2.0.2 are commonly
  737.      available, but they have a bug that shows up when compiling current
  738.      versions of GNU CC: undefined symbol errors occur during assembly
  739.      if you use `-g'.
  740.      The solution is to compile the current version of GNU CC without
  741.      `-g'.  That makes a working compiler which you can use to recompile
  742.      with `-g'.
  743.    * Solaris 2 comes with a number of optional OS packages.  Some of
  744.      these packages are needed to use GNU CC fully.  If you did not
  745.      install all optional packages when installing Solaris, you will
  746.      need to verify that the packages that GNU CC needs are installed.
  747.      To check whether an optional package is installed, use the
  748.      `pkginfo' command.  To add an optional package, use the `pkgadd'
  749.      command.  For further details, see the Solaris documentation.
  750.      For Solaris 2.0 and 2.1, GNU CC needs six packages: `SUNWarc',
  751.      `SUNWbtool', `SUNWesu', `SUNWhea', `SUNWlibm', and `SUNWtoo'.
  752.      For Solaris 2.2, GNU CC needs an additional seventh package:
  753.      `SUNWsprot'.
  754.    * On Solaris 2, trying to use the linker and other tools in
  755.      `/usr/ucb' to install GNU CC has been observed to cause trouble.
  756.      For example, the linker may hang indefinitely.  The fix is to
  757.      remove `/usr/ucb' from your `PATH'.
  758.    * If you use the 1.31 version of the MIPS assembler (such as was
  759.      shipped with Ultrix 3.1), you will need to use the
  760.      -fno-delayed-branch switch when optimizing floating point code.
  761.      Otherwise, the assembler will complain when the GCC compiler fills
  762.      a branch delay slot with a floating point instruction, such as
  763.      `add.d'.
  764.    * If on a MIPS system you get an error message saying "does not have
  765.      gp sections for all it's [sic] sectons [sic]", don't worry about
  766.      it.  This happens whenever you use GAS with the MIPS linker, but
  767.      there is not really anything wrong, and it is okay to use the
  768.      output file.  You can stop such warnings by installing the GNU
  769.      linker.
  770.      It would be nice to extend GAS to produce the gp tables, but they
  771.      are optional, and there should not be a warning about their
  772.      absence.
  773.    * In Ultrix 4.0 on the MIPS machine, `stdio.h' does not work with GNU
  774.      CC at all unless it has been fixed with `fixincludes'.  This causes
  775.      problems in building GNU CC.  Once GNU CC is installed, the
  776.      problems go away.
  777.      To work around this problem, when making the stage 1 compiler,
  778.      specify this option to Make:
  779.           GCC_FOR_TARGET="./xgcc -B./ -I./include"
  780.      When making stage 2 and stage 3, specify this option:
  781.           CFLAGS="-g -I./include"
  782.    * Users have reported some problems with version 2.0 of the MIPS
  783.      compiler tools that were shipped with Ultrix 4.1.  Version 2.10
  784.      which came with Ultrix 4.2 seems to work fine.
  785.      Users have also reported some problems with version 2.20 of the
  786.      MIPS compiler tools that were shipped with RISC/os 4.x.  The
  787.      earlier version 2.11 seems to work fine.
  788.    * Some versions of the MIPS linker will issue an assertion failure
  789.      when linking code that uses `alloca' against shared libraries on
  790.      RISC-OS 5.0, and DEC's OSF/1 systems.  This is a bug in the
  791.      linker, that is supposed to be fixed in future revisions.  To
  792.      protect against this, GNU CC passes `-non_shared' to the linker
  793.      unless you pass an explicit `-shared' or `-call_shared' switch.
  794.    * On System V release 3, you may get this error message while
  795.      linking:
  796.           ld fatal: failed to write symbol name SOMETHING
  797.            in strings table for file WHATEVER
  798.      This probably indicates that the disk is full or your ULIMIT won't
  799.      allow the file to be as large as it needs to be.
  800.      This problem can also result because the kernel parameter `MAXUMEM'
  801.      is too small.  If so, you must regenerate the kernel and make the
  802.      value much larger.  The default value is reported to be 1024; a
  803.      value of 32768 is said to work.  Smaller values may also work.
  804.    * On System V, if you get an error like this,
  805.           /usr/local/lib/bison.simple: In function `yyparse':
  806.           /usr/local/lib/bison.simple:625: virtual memory exhausted
  807.      that too indicates a problem with disk space, ULIMIT, or `MAXUMEM'.
  808.    * Current GNU CC versions probably do not work on version 2 of the
  809.      NeXT operating system.
  810.    * On NeXTStep 3.0, the Objective C compiler does not work, due,
  811.      apparently, to a kernel bug that it happens to trigger.  This
  812.      problem does not happen on 3.1.
  813.    * On the Tower models 4N0 and 6N0, by default a process is not
  814.      allowed to have more than one megabyte of memory.  GNU CC cannot
  815.      compile itself (or many other programs) with `-O' in that much
  816.      memory.
  817.      To solve this problem, reconfigure the kernel adding the following
  818.      line to the configuration file:
  819.           MAXUMEM = 4096
  820.    * On HP 9000 series 300 or 400 running HP-UX release 8.0, there is a
  821.      bug in the assembler that must be fixed before GNU CC can be
  822.      built.  This bug manifests itself during the first stage of
  823.      compilation, while building `libgcc2.a':
  824.           _floatdisf
  825.           cc1: warning: `-g' option not supported on this version of GCC
  826.           cc1: warning: `-g1' option not supported on this version of GCC
  827.           ./xgcc: Internal compiler error: program as got fatal signal 11
  828.      A patched version of the assembler is available by anonymous ftp
  829.      from `altdorf.ai.mit.edu' as the file
  830.      `archive/cph/hpux-8.0-assembler'.  If you have HP software support,
  831.      the patch can also be obtained directly from HP, as described in
  832.      the following note:
  833.           This is the patched assembler, to patch SR#1653-010439, where
  834.           the assembler aborts on floating point constants.
  835.           The bug is not really in the assembler, but in the shared
  836.           library version of the function "cvtnum(3c)".  The bug on
  837.           "cvtnum(3c)" is SR#4701-078451.  Anyway, the attached
  838.           assembler uses the archive library version of "cvtnum(3c)"
  839.           and thus does not exhibit the bug.
  840.      This patch is also known as PHCO_4484.
  841.    * On HP-UX version 8.05, but not on 8.07 or more recent versions,
  842.      the `fixproto' shell script triggers a bug in the system shell.
  843.      If you encounter this problem, upgrade your operating system or
  844.      use BASH (the GNU shell) to run `fixproto'.
  845.    * Some versions of the Pyramid C compiler are reported to be unable
  846.      to compile GNU CC.  You must use an older version of GNU CC for
  847.      bootstrapping.  One indication of this problem is if you get a
  848.      crash when GNU CC compiles the function `muldi3' in file
  849.      `libgcc2.c'.
  850.      You may be able to succeed by getting GNU CC version 1, installing
  851.      it, and using it to compile GNU CC version 2.  The bug in the
  852.      Pyramid C compiler does not seem to affect GNU CC version 1.
  853.    * There may be similar problems on System V Release 3.1 on 386
  854.      systems.
  855.    * On the Intel Paragon (an i860 machine), if you are using operating
  856.      system version 1.0, you will get warnings or errors about
  857.      redefinition of `va_arg' when you build GNU CC.
  858.      If this happens, then you need to link most programs with the
  859.      library `iclib.a'.  You must also modify `stdio.h' as follows:
  860.      before the lines
  861.           #if     defined(__i860__) && !defined(_VA_LIST)
  862.           #include <va_list.h>
  863.      insert the line
  864.           #if __PGC__
  865.      and after the lines
  866.           extern int  vprintf(const char *, va_list );
  867.           extern int  vsprintf(char *, const char *, va_list );
  868.           #endif
  869.      insert the line
  870.           #endif /* __PGC__ */
  871.      These problems don't exist in operating system version 1.1.
  872.    * On the Altos 3068, programs compiled with GNU CC won't work unless
  873.      you fix a kernel bug.  This happens using system versions V.2.2
  874.      1.0gT1 and V.2.2 1.0e and perhaps later versions as well.  See the
  875.      file `README.ALTOS'.
  876.    * You will get several sorts of compilation and linking errors on the
  877.      we32k if you don't follow the special instructions.  *Note
  878.      Configurations::.
  879.    * A bug in the HP-UX 8.05 (and earlier) shell will cause the fixproto
  880.      program to report an error of the form:
  881.           ./fixproto: sh internal 1K buffer overflow
  882.      To fix this, change the first line of the fixproto script to look
  883.      like:
  884.           #!/bin/ksh
  885.